<template>
  <div style="width:100%;height:100%">
    <v-chart :options="option" :initOptions="initOptions" :theme="theme" autoresize />
  </div>
</template>
<script>

export default {
  name: 'chart',
  props: ['index'],
  mounted () {
  },
  data () {
    return {
      initOptions: { renderer: 'canvas' },
      theme: 'default'
    }
  },
  methods: {
  },
  computed: {
    insideSlideArray () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent
    },
    insideArrayIndex () {
      return this.insideSlideArray.indexOf(this.insideSlideArray.filter((currentValue) => {
        return currentValue.i === this.index
      })[0])
    },
    getDetail () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent[this.insideArrayIndex].itemContent.detail
    },
    getSeries () {
      var series = []
      for (let i = 0, nc = this.getDetail.nc - 1; i < nc; i++) {
        series.push({
          type: 'bar',
          ...this.getDetail.simpleBar,
          backgroundStyle: {
            color: this.getDetail.simpleBar.backgroundStyle[this.getDetail.simpleBar.backgroundStyle.option]
          }
        })
      }
      return series
    },
    option () {
      return {
        animation: this.getDetail.animation,
        title: this.getDetail.title,
        legend: this.getDetail.legend,
        tooltip: {},
        dataset: {
          source: this.getDetail.sheetData
        },
        xAxis: this.getDetail.xAxis,
        yAxis: this.getDetail.yAxis,
        series: this.getSeries,
        color: this.getDetail.color[this.getDetail.color.option],
        grid: this.getDetail.grid,
        label: this.getDetail.label,
        itemStyle: this.getDetail.itemStyle,
        emphasis: this.getDetail.emphasis,
        backgroundColor: this.getDetail.backgroundColor[this.getDetail.backgroundColor.option]
      }
    }
  }
}
</script>
<style scoped>
  .echarts {
    width: 100%;
    height: 100%;
  }
</style>
<style>

</style>
